package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.bean.User;
import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;

@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String message = req.getParameter("message");
		String user_password = req.getParameter("user_password");
		if(message == "" || user_password=="") {
			resp.sendRedirect("login.jsp");
			return;
		}
		UserService us = new UserServiceImpl();
		User u = us.login(message, user_password);
		if(u == null) {
			resp.sendRedirect("login.jsp");
			return;
		}else {
			req.getSession().setAttribute("loginUser", u);
			resp.sendRedirect("homepage.jsp");
			return;
		}
	}
}
